﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jxym.DBUtility;
using Jxym.Common.JSON;
using Newtonsoft.Json;
using Jxym.wlkc2011.Module.Default.model;

namespace Jxym.wlkc2011.Module.Default.SERVER.role
{
    public partial class RoleTree : System.Web.UI.Page
    {
        string str = "", isChecked = "", strwhere = "";

        MsSqlDal<User_Role> iur = new MsSqlDal<User_Role>();
        MsSqlDal<User_RoleConfig> iurc = new MsSqlDal<User_RoleConfig>();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Params["userid"] != null)
                {
                    strwhere = "UserID=" + Request.Params["userid"];
                    IList<User_RoleConfig> list = iurc.GetList(strwhere, null, "", 0);
                    str = "";
                    foreach (User_RoleConfig c in list)
                    {
                        str += c.RoleID + ",";
                    }
                    str = str.TrimEnd(',');
                }
                else
                {
                    if (Request.Params["checked"] != null)
                    {
                        isChecked = "'checked':" + Request.Params["checked"] + ",";
                    }
                    IList<User_Role> iClist = iur.GetList("", null, "", 0);
                    str = "[";
                    foreach (User_Role c in iClist)
                    {
                        str += "{" + isChecked + "'id':" + c.ID + ",'text':'" + c.Name + "','leaf':true,'iconCls':'icon-group-16'},";
                    }
                    str = str.TrimEnd(',');
                    str += "]";
                }
                Response.Write(str);
            }
        }
    }
}